package com.ftg.learn.chapter07.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ftg.learn.chapter07.entity.User;
import com.ftg.learn.chapter07.mapper.UserMapper;
import com.ftg.learn.chapter07.service.IUserService;
import com.ftg.learn.chapter07.util.MapperUtil;
import com.ftg.learn.chapter07.util.ServiceUtil;
import com.ftg.learn.chapter07.vo.UserEmpVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author kangjx
 * @createTime 2022/11/10
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Resource
    MapperUtil mapperUtil;

    @Resource
    ServiceUtil<UserEmpVo> serviceUtil;

    @Override
    public List<Map<String, Object>> userEmpClassList() {
        System.out.println(mapperUtil.getCount("select * from sys_user"));
        return mapperUtil.manyTableForList("\n" +
                "select sys_user.id, u_account, u_password, e_id, sys_user.is_deleted, sys_user.gmc_create, sys_user.gmc_update,emp_name, emp_sex, emp_code, emp_type, emp_job, emp_birthday, clazz_name  from sys_user left join sys_employee se on sys_user.e_id = se.id\n" +
                "left join sys_clazz sc on se.clazz_id = sc.id");
    }

    @Override
    public Map<String, Object> manyTableForOne(int id) {
        return mapperUtil.manyTableForOne("select * from sys_user where id = " + id);
    }

    @Override
    public List<UserEmpVo> userempList() {
        return serviceUtil.query("select  u_account uaccount, emp_name empName,clazz_name className  " +
                "from sys_user left join sys_employee se on sys_user.e_id = se.id left join sys_clazz sc on se.clazz_id = sc.id",UserEmpVo.class);
    }


}
